<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net 
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : article.php   FILE_PATH : member\article.php
 * ....会员后台文章管理页面
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Wed Aug 15 16:09:46 CST 2007
 */
require ("../global.inc.php");

class OwnArticleManage extends CommonFrameWork{

	/**
	 * 文章对象
	 *
	 * @var obj
	 */
	var $obj_article;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;

	function main(){
		/**
		 * 创建文章对象
		 */
		if (!is_object($this->obj_article)){
			require_once("article.class.php");
			$this->obj_article = new ArticleClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("member");

		/**
		 * 语言包
		 */
		$this->getlang("article");

		switch ($this->_input['action']){
			case "list":
				$this->_listarticle();
				break;
			case "add":
				$this->_addarticle();
				break;
			case "save":
				$this->_savearticle();
				break;
			case "modi":
				$this->_modiarticle();
				break;
			case "update":
				$this->_updatearticle();
				break;
			case "del":
				$this->_delarticle();
				break;
			default:
				$this->_listarticle();
				break;
		}

	}

	/**
	 * 文章列表
	 *
	 */
	function _listarticle(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();

		/**
		 * 取得查询参数
		 */
		$obj_condition[key] = $this->_input['keyword'];
		$obj_condition[keygenre] = $this->_input['searchtype'];
		
		/**
		 * 取得文章列表
		 */
		$obj_page->pagebarnum(15);
		$article_array = $this->obj_article->getArticleList($obj_condition,$obj_page);
		$page_list = $obj_page->show(1);
		/**
		 * 输出到页面模板
		 */
		$this->output("page_list", $page_list);
		$this->output("article_array",$article_array);
		$this->showpage("own_article.manage");
	}
	/**
	 * 文章添加页面
	 *
	 */
	function _addarticle(){
		$this->output("article_type", "关于我们");
		$this->showpage("own_article.add");
	}
	/**
	 * 保存文章
	 *
	 */
	function _savearticle(){
		/**
		 * 店铺ID暂时默认为0
		 * 文章状态暂时默认为1
		 */
		$this->_input["txtShopid"] = 0;
		$this->_input["txtArticlestate"] = 1;
		/**
		 * 验证表单信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtArticletitle"],"require"=>"true","message"=>$this->_lang['errArticleTitle']),
		array("input"=>$this->_input["txtArticletype"],"require"=>"true","message"=>$this->_lang['errArticleType']),
		array("input"=>$this->_input["txtArticlecontent"],"require"=>"true","message"=>$this->_lang['errArticleContent']));
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$result = $this->obj_article->addArticle($this->_input);
			echo "ok";
		}
	}
	/**
	 * 文章编辑页面
	 *
	 */
	function _modiarticle(){
		$article_array = $this->obj_article->getArticleRow($this->_input["articleid"]);
		$this->output("article_array",$article_array);
		$this->showpage("own_article.add");
	}
	/**
	 * 更新文章
	 *
	 */
	function _updatearticle(){
		/**
		 * 文章状态暂时默认为1
		 */
		$this->_input["txtArticlestate"] = 1;
		/**
		 * 验证表单信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtArticletitle"],"require"=>"true","message"=>$this->_lang['errArticleTitle']),
		array("input"=>$this->_input["txtArticlecontent"],"require"=>"true","message"=>$this->_lang['errArticleContent']));
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$result = $this->obj_article->updateArticle($this->_input);
			echo "ok";
		}
	}
	/**
	 * 删除文章
	 *
	 */
	function _delarticle(){
		/**
		 * 验证文章ID
		 */
		foreach ($this->_input['chboxArticleid'] as $value){
			$this->objvalidate->setValidate(array("input"=>$value,"validator"=>"Number","message"=>$this->_lang['errArticleId']));
		}
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$result = $this->obj_article->delArticle($this->_input['chboxArticleid']);
			echo "ok";
		}
	}
}

$article_manage = new OwnArticleManage();
$article_manage->main();
unset($article_manage);
?>